<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class IzapProfileVisitors {
    public $user;
    public $visitor;
    public function __construct($user,$visitor){

        $this->user=$user;
        $this->visitor=$visitor;
    }


    
    public function trackvisitors(){

        $current_visitor=$this->getvisitor($this->visitor);
        $current_visitor_temp=new ElggObject($current_visitor->guid);
        $current_visitor_temp->access_id=ACCESS_LOGGED_IN;
        $current_visitor_temp->subtype=GLOBAL_IZAP_VISITORS_SUBTYPE;
        $current_visitor_temp->total_visits=(int) $current_visitor->total_visits + 1;
        $current_visitor_temp->title=$this->visitor->name.' visited u '.$current_visitor_temp->total_visits.' times';
        $current_visitor_temp->description=$this->visitor->name;
        $current_visitor_temp->visited=$this->user->guid;

        $current_visitor_temp->save();
        
        }

    public function getvisitor($visitor){

        $returned_visitor= elgg_get_entities_from_metadata(array(
                'type'=>'object',
                'subtype'=>GLOBAL_IZAP_VISITORS_SUBTYPE,
                'metadata_name'=>'visited',
                'metadata_value'=>$user->guid,
                'container_guid'=>$visitor->guid,
                'limit'=>1
            ));
        if($returned_visitor)

            return $returned_visitor[0];

          }
}